#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 8e5 + 10, INF = 0x3f3f3f3f;

int n, m, root;
struct node
{
    int ls, rs, pri, size;
    int sum, val, f, c;
    int pre, suf, mx;
}t[N];
int avai[N], tt = 0;

int newnode(int v)
{
    int x = avai[tt--];
    t[x].ls = t[x].rs = t[x].f = 0;
    t[x].c = INF;
    t[x].pre = t[x].suf = max(v, 0);
    t[x].sum = t[x].val = t[x].mx = v;
    t[x].pri = rand();
    t[x].size = 1;
    return x;
}

void rever(int x)
{
    swap(t[x].ls, t[x].rs);
    swap(t[x].pre, t[x].suf);
    t[x].f ^= 1;
}

void make(int x, int c)
{
    t[x].val = c;
    t[x].sum = c * t[x].size;
    t[x].pre = t[x].suf = max(t[x].sum, 0);
    t[x].mx = max(t[x].sum, c);
    t[x].c = c;
}

void pushup(int x)
{
    if (x == 0) return;
    int ls = t[x].ls, rs = t[x].rs;
    t[x].size = t[ls].size + t[rs].size + 1;
    t[x].sum = t[ls].sum + t[rs].sum + t[x].val;

    t[x].pre = max({ t[ls].pre, t[ls].sum + t[rs].pre + t[x].val,0 });
    t[x].suf = max({ t[rs].suf, t[rs].sum + t[ls].suf + t[x].val,0 });

    t[x].mx = t[ls].suf + t[rs].pre + t[x].val;
    if (ls) t[x].mx = max(t[x].mx, t[ls].mx);
    if (rs) t[x].mx = max(t[x].mx, t[rs].mx);
}

void pushdown(int x)
{
    if (t[x].c != INF) {
        if (t[x].ls) make(t[x].ls, t[x].c);
        if (t[x].rs) make(t[x].rs, t[x].c);
        t[x].c = INF;
    }
    if (t[x].f) {
        if (t[x].ls) rever(t[x].ls);
        if (t[x].rs) rever(t[x].rs);
        t[x].f = 0;
    }
}

void split(int x, int k, int& l, int& r)
{
    if (x == 0) { l = r = 0; return; }
    pushdown(x);
    if (t[t[x].ls].size + 1 <= k) {
        l = x;
        split(t[x].rs, k - t[t[x].ls].size - 1, t[x].rs, r);
    } else {
        r = x;
        split(t[x].ls, k, l, t[x].ls);
    }
    pushup(x);
}

int merge(int l, int r)
{
    if (l == 0 || r == 0) return l + r;
    if (t[l].pri > t[r].pri) {
        pushdown(l);
        t[l].rs = merge(t[l].rs, r);
        pushup(l);
        return l;
    } else {
        pushdown(r);
        t[r].ls = merge(l, t[r].ls);
        pushup(r);
        return r;
    }
}

int a[N];
int build(int l, int r)
{
    if (l == r) return newnode(a[l]);
    int mid = (l + r) >> 1;
    return merge(build(l, mid), build(mid + 1, r));
}

void reuse(int x)
{
    if (x == 0) return;
    reuse(t[x].ls);
    reuse(t[x].rs);
    avai[++tt] = x;
}

void debug(int x) {
    if (!x) return;
    pushdown(x);  // 确保 lazy 被下传
    debug(t[x].ls);
    cout << "idx = " << x
        << ", val = " << t[x].val
        << ", ls = " << t[x].ls
        << ", rs = " << t[x].rs
        << ", size = " << t[x].size
        << ", sum = " << t[x].sum
        << ", pre = " << t[x].pre
        << ", suf = " << t[x].suf
        << ", mx = " << t[x].mx
        << ", f = " << t[x].f
        << ", c = " << t[x].c
        << '\n';
    debug(t[x].rs);
}

void solve()
{
    for (int i = N - 1;i >= 1;i--) avai[++tt] = i;
    cin >> n >> m;
    for (int i = 1;i <= n;i++) cin >> a[i];
    root = build(1, n);
    char op[10];int pos, len, l, r, p;
    while (m--) {
        cin >> op;l = r = p = 0;
        if (op[0] == 'I') {
            cin >> pos >> len;
            for (int i = 1;i <= len;i++) cin >> a[i];
            split(root, pos, l, r);
            p = build(1, len);
            root = merge(merge(l, p), r);
        }
        if (op[0] == 'D') {
            cin >> pos >> len;
            split(root, pos + len - 1, l, r); split(l, pos - 1, l, p);
            reuse(p);
            root = merge(l, r);
        }
        if (op[0] == 'M' && op[2] == 'K') {
            int v; cin >> pos >> len >> v;
            split(root, pos + len - 1, l, r); split(l, pos - 1, l, p);
            pushdown(p);
            make(p, v);
            root = merge(merge(l, p), r);
        }
        if (op[0] == 'R') {
            cin >> pos >> len;
            split(root, pos + len - 1, l, r); split(l, pos - 1, l, p);
            pushdown(p);
            rever(p);
            root = merge(merge(l, p), r);
        }
        if (op[0] == 'G') {
            cin >> pos >> len;
            split(root, pos + len - 1, l, r); split(l, pos - 1, l, p);
            cout << t[p].sum << '\n';
            root = merge(merge(l, p), r);
        }
        if (op[0] == 'M' && op[2] == 'X') cout << t[root].mx << '\n';
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    srand(time(NULL));
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}